import fetch from 'common/src/utils/fetch';
/**
 * 获取学期
 */
export function getTeamList(id) {
    return fetch({
        url: '/api/baseresservice/schoolCalendar/list',
        method: 'get',
        params: {
            year: id
        }
    });
}

export function findPublicelective(data) {
    return fetch({
        url: '/api/arrangementservice/publicelective/findPublicelective2',
        method: 'post',
        headers: { 'Content-Type': 'application/json' },
        data
    })
}

export function findMinorCourse(data) {
  return fetch({
      url: '/api/arrangementservice/publicelective/findMinorCourse',
      method: 'post',
      headers: { 'Content-Type': 'application/json' },
      data
  })
}

/**
 * 开课
 * @param {data} data
 */
export function openPublicelective(data) {
    return fetch({
        url: '/api/arrangementservice/publicelective/openPublicelective',
        method: 'post',
        headers: { 'Content-Type': 'application/json' },
        data
    })
}

/**
 * 辅修微专业开课
 * @param {data} data
 */
export function openMinorCourse(data) {
  return fetch({
      url: '/api/arrangementservice/publicelective/openMinorCourse',
      method: 'post',
      headers: { 'Content-Type': 'application/json' },
      data
  })
}

/**
 * 取消开课
 * @param {data} data
 */
export function deOpenPublicelective(data) {
    return fetch({
        url: '/api/arrangementservice/publicelective/deOpenPublicelective',
        method: 'post',
        headers: { 'Content-Type': 'application/json' },
        data
    })
}

/**
 * 取消辅修微专业开课
 * @param {*} data
 */
export function deOpenMinorCourse(data) {
  return fetch({
      url: '/api/arrangementservice/publicelective/deOpenMinorCourse',
      method: 'post',
      headers: { 'Content-Type': 'application/json' },
      data
  })
}


/**
 * 删除开课
 * @param {data} data
 */
export function deletePublicelective(data) {
    return fetch({
        url: '/api/arrangementservice/publicelective/deletePublicelective',
        method: 'delete',
        headers: { 'Content-Type': 'application/json' },
        data
    })
}

/**
 * 删除辅修微专业课程
 * @param {*} data
 */
export function deleteMinorCourse(data) {
  return fetch({
      url: '/api/arrangementservice/publicelective/deleteMinorCourse',
      method: 'delete',
      headers: { 'Content-Type': 'application/json' },
      data
  })
}

/**
 * 同步公选课
 * @param {data} data
 */
export function synchronPublicelective(calendarId) {
    return fetch({
        url: '/api/arrangementservice/publicelective/synchronPublicelective?calendarId='+calendarId,
        method: 'get'
    })
}

/**
 * 同步公选课状态
 */
export function getStatus(key) {
    return fetch({
        url:'/api/arrangementservice/publicelective/findSyndromeStatus?key='+key,
        method: 'get'
    });
}

/**
 * 导出公选课
 * @param {data} data
 */
export function findPublicElectiveCourseExport(params) {
    let url = "/api/arrangementservice/publicelective/findPublicElectiveCourseExport";
    let queryParam = '';
    for (let key in params) {
        // 去掉空参数
        if (params[key] === "") {
            continue;
        }
        queryParam += `${key}=${params[key]}&`;
    }
    console.log(queryParam);
    window.open(`${url}?${queryParam}`);
}

/**
 * 导出辅修微专业开课
 */
export function minorCourseExport(data) {
  return fetch({
    url: '/api/arrangementservice/publicelective/minorCourseExport',
    method: 'post',
    data:data
  });
}

/**
 * 辅修微专业的异步状态
 * @param {*} key
 */
export function getReportStatus(key) {
  return fetch({
    url: '/api/arrangementservice/NonPublicCourseOpen/result/' + key,
    method: 'get'
  });
}
